﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace RclSystem
{
    public partial class CompanyDialog : UIEditForm
    {
        public CompanyDialog()
        {
            InitializeComponent();
            DataTable dataTable = MySQLHelper.ExecuteQuery("SELECT * FROM tbl_saleman");
            cb_saleman.DataSource = dataTable;
            cb_saleman.DisplayMember = "name";
            cb_saleman.ValueMember = "id";
        }

        protected override bool CheckData()
        {
            return CheckEmpty(txt_name, "请输入单位名称") && CheckEmpty(cb_saleman, "请选择业务员");
        }

        private CompanyEntity company;

        public CompanyEntity CompanyEntity
        {
            get
            {
                if (company == null)
                {
                    company = new CompanyEntity();
                }

                company.name = txt_name.Text;
                company.parentid = long.Parse(cb_saleman.SelectedValue.ToString());
                company.initalamount = double.Parse(txt_initalamount.Text);
                return company;
            }

            set
            {
                company = value;
                txt_name.Text = value.name;
                cb_saleman.SelectedValue = value.parentid;
                txt_initalamount.Text = value.initalamount.ToString();
            }
        }
    }
}
